export class ArrayUtil {
  static handleRemoveRepeat = (arr: any[]) => arr.filter((item, index) => arr.indexOf(item, 0) === index)
  static handleRemoveRepeatAndFilter = (arr: any[]) =>
    arr.filter((item, index) => item && arr.indexOf(item, 0) === index)
  static isEmptyArray = (arr: any[]) => arr.length === 0
  static addUniqueKeyToTree = (arr: any[], pid = '') => {
    const format = (arr, pid = '') => {
      return arr.map(item => {
        const value = `${pid ? `${pid}-` : ''}${item.id}`
        return {
          ...item,
          value,
          ...(item.children
            ? {
                children: format(item.children, value)
              }
            : {})
        }
      })
    }
    return format(arr, pid)
  }
}
